<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!-- zTreeStyle.css -->
<link rel="stylesheet" type="text/css" href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
<style type="text/css">
* {
	margin: 0px;
	padding: 0px;
	font-size: 12px;
}
</style>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;系统管理&gt;基础信息管理&gt;面签配置</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content">
			<button type="button" class="btn dpbtn_green" onclick="add();">新增</button>
		</div>
		<div class="ibox-content">
			<div role="form" class="form-inline">
				<div class="form-group">
					<input type="text" placeholder="机构名称" class="form-control" id="orgName" name="orgName" />
				</div>
				<div class="form-group">
					<select class="form-control" style="width:180px;" id="interviewConfigStatusDis" onchange="query();"></select>
				</div>
				<button class="zhixcx" type="button" onclick="query();">执行查询</button>
			</div>
		</div>
		<div class="ibox-content">
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>

	<div id="mianQianset" style="display: none;">
		<form class="form-horizontal m-t" id="commentForm">
			<div class="business-padding">
				<div class="form-group">
					<label class="col-sm-3 control-label">资金渠道：</label>
					<div class="col-sm-8">
						<select id="interviewConfigStatus" class="select-control"></select>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">机构名称：</label>
					<div class="col-sm-8">
						<input type="hidden" id="id" name="id" /> 
						<input type="hidden" id="busiUnitId" name="busiUnitId" /> 
						<input id="busiUnitCode" type="hidden"/>
						<input id="busiUnitName" readonly="readonly" class="form-control smalliconcur smallicon colorred" type="text" onclick="jigouCodeCho()" />
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-sm-3 control-label">贷款银行：</label>
					<div class="col-sm-8">
						<select id="bankCode" name="bankCode" class="form-control">
						</select>
					</div>
				</div>
				<table cellpadding="0" cellspacing="0" border="0"
					bordercolor="#3B95C8" width="100%">
					<tr>
						<td width="100%" align="center">
							<div class="ibox-content">
								<button type="button" class="btn dpbtn_green" onclick="save();">确定</button>
							</div>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>
	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>
	<!--zTreeStyle.js-->
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.core.js" charset="utf-8"></script>
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.excheck.js" charset="utf-8"></script>

	<script type="text/javascript">
	jQuery(function ($) {
	    getData();
	    initData();
	});
	
	//初始化
	function initData(){
		$.dpAjax({
			show:false,
	    	url:'${basePath}/DataDictionaryController/getEnableList',
 			data:{parentValue:'Interview_Config_Status'},
 			success: function(datas){
 				var result = datas.result.rows;
				var html='<option value="" selected>请选择...</option>';
			    for(var i=0;i<result.length;i++){
				    html +='<option value="'+result[i].value+'">'+result[i].name+'</option>'
			    }
			    $("#interviewConfigStatus").html(html);
			    $("#interviewConfigStatusDis").html(html);
				return;
            }
	    });
		$.dpAjax({
	    	url:'${basePath}/DataDictionaryController/getEnableList',
	    	data:{parentValue:'LoanBank'},
 			success: function(datas){
 				var result = datas.result.rows;
 				var html='<option value="" selected>请选择...</option>';
			    for(var i=0;i<result.length;i++){
				    html +='<option value="'+result[i].value+'">'+result[i].name+'</option>'
			    }
			    $("#bankCode").html(html);
				return;
            }
	    });
	}
	
    //条件搜索
    var query = function()
    {
    	var data={};
    	var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
    	data.orgName = document.getElementById('orgName').value || '';
    	data.interviewConfigStatus = document.getElementById('interviewConfigStatusDis').value || '';
    	$.extend(postData, data);
    	refresh();
    }

    var getData = function () {
 		var winWidth = $('div.ibox-content').width();
   	    var winHeight = document.body.offsetHeight - 300;
	    var win = winWidth / 7 - 20;
        $.jgrid.defaults.styleUI = 'Bootstrap';

        jQuery("#table_list_1").jqGrid
        ({
            url: '${basePath}/OtherInterviewConfigController/multilist',//表单接口需要换
            datatype: "json",
            colNames: ['主键','机构编码','机构名称','面签配置','面签状态','银行code','贷款银行'],
            colModel: [
				{name: 'replaceId', index: 'IC.id', hidden:true},
                {name: 'busiUnitCode', sortable:false, width: 100, hidden:true},
                {name: 'orgName', index: 'BU.orgName', width: 100, align: "center"},
                {name: 'interviewConfigStatusDisplay', index: 'IC.interviewConfigStatus', width: 80, align: "center"},
                {name: 'interviewConfigStatus', hidden:true},
                {name: 'bankCode',  hidden:true},
                {name: 'bankCodeDisplay', index: 'IC.bankCode', width: 100, align: "center"}
            ],
            mtype: "post",
            height: winHeight,
            width:winWidth,  
            autowidth: true,
            shrinkToFit: true,
            rowNum: 15,
            sortorder : "desc",
            sortname : 'created',
            rowList: [15, 30, 45],
            viewrecords: true,
            pager: "#pager_list_1",
            hidegrid: false,
            multiselect: false,
            altRows:true,
            altclass:'someClass',
            ondblClickRow:function(rowId,v,e)
            {	
	          	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
	          	  var id = rowData.replaceId;
	          	  var busiUnitCode = rowData.busiUnitCode;
	          	  var interviewConfigStatus = rowData.interviewConfigStatus;
	          	  $("#id").val(id);
	          	  $("#busiUnitCode").val(rowData.busiUnitCode);
	          	  $("#busiUnitName").val(rowData.orgName);
	          	  $("#busiUnitId").val(rowData.busiUnitId);
	          	  $("#interviewConfigStatus").val(rowData.interviewConfigStatus);
	          	  $('#bankCode').val(rowData.bankCode);
	          	  updateLayer =  layer.open({
	  		    	  type: 1,
	  		    	  title: '面签配置',
	  		    	  shadeClose: true,
	  		    	  shade: 0.8,
	  		    	  area: ['450px', '350px'],
	  		    	  content: $("#mianQianset"),
		  		    	end: function () { 
		  	    		  $('#id').val('');
		  	    		  $('#busiUnitId').val('');
		  	    		  $('#busiUnitCode').val('');
		  	    		  $('#busiUnitName').val('');
		  	    		  $('#bankCode').val('');
		  	    		  refresh();
		  	          }
	  	    	});  	  
            },
            jsonReader: {
                root: "result.rows",
                page: "result.page",
                total: "result.total",
                records: "result.records",
                repeatitems: false,
                id: "replaceId"
            },
            loadComplete:function(datas){
          	  if (datas.flag == "100100") {
                    layer.msg("查询成功!", {icon: 6, time: 1000});
                    return;
                }
          	  if(datas.flag == '100802') {
  				  top.location.href = thisLoginUrl;
  				  return;
  			  }

          	  layer.msg(datas.message, {icon: 2});
            }
        });
    }
	
    var ywjigou;
    
    function jigouCodeCho(){
	    $.dpAjax({
	  		show:false,
			url:'${basePath}/BaseBusiUnitController/list',
			data:{dpStatus:1},
			success: function(datas){
				var content = '<div class="ibox-content" style="height: 380px;border: 1px solid #F5F5F6; overflow:auto;overflow-x: hidden;">'
				+ '	<div id="orgtreeDemo" class="ztree">&nbsp;</div>'
				+ '</div>'
				+ '<div class="ibox-content">'
				+ '<button class="btn dpbtn_green" type="button" onclick="confirmOrg();">确定</button>&nbsp;'
				+ '<button class="btn dpbtn_red" type="button" onclick="cancelOrg();">取消</button>'
				+ '</div>';
		
		    ywjigou = layer.open({
		    	  title:'业务机构',
		    	  type: 1,
		    	  area: ['600px', '500px'], //宽高
		    	  content: content
		    });
	    	
		    var setting = {
				check: {
					enable: false
				},
				data: {
					simpleData: {
						enable: true
					},
				}
		    };			
		    var  arr = [];
		    var d = datas.result.rows;
		    for(var i=0;i<d.length;i++)
		    {  
			  var r = d[i];
			  var objs = {};
			  objs.id = r.replaceId;
			  objs.pId = r.parentId;
			  objs.orgCode=r.orgCode;
			  objs.parentCode=r.parentCode;
			  objs.name = r.orgName;
			  
			  if(r.replaceId == 1){
     		  	 objs.open = true;
			  } else {
				 objs.open = false; 
			  }
			  arr.push(objs);
			}  
		    zTrees_ = $.fn.zTree.init($("#orgtreeDemo"), setting, arr);
		    return;
		  }
	   });
    }
    
    var confirmOrg = function()
    {
		var treeObj = $.fn.zTree.getZTreeObj("orgtreeDemo");
		var nodes = treeObj.getSelectedNodes();
		var treeNode = nodes[0];
        var length = nodes.length;
        if(treeNode.id == 1) {
        	layer.msg('无法选择顶级机构',{icon:7});
        	return;
        }
        if(length != 1) {
        	layer.msg('请选择一个机构节点',{icon:7});
        	return;
        }
        $("#busiUnitCode").val(treeNode.orgCode);
        $("#busiUnitName").val(treeNode.name);
        $("#busiUnitId").val(treeNode.id);
        layer.close(ywjigou);
    }
    
    
    //新增
    var addlayer;
    var add = function () {
    	
    	$('#busiUnitCode').val("");
    	$('#busiUnitName').val("");
    	$('#busiUnitId').val("");
    	
    	addlayer=layer.open({
            type: 1,
            title: '面签配置',
            shadeClose: true,
            shade: 0.8,
            area: ['450px', '350px'],
            content: $("#mianQianset"),
	    	end: function () { 
	    		  $('#id').val('');
	    		  $('#busiUnitId').val('');
	    		  $('#busiUnitCode').val('');
	    		  $('#busiUnitName').val('');
	    		  $('#bankCode').val('');
	    		  refresh();
	          }
        });
    }
    
    
    //保存
    var save = function()
    {
     	var url;
     	var data = {};
     	var id = $('#id').val();
     	data.busiUnitCode = $('#busiUnitCode').val();
     	data.interviewConfigStatus = $('#interviewConfigStatus').val();
     	data.busiUnitId = $('#busiUnitId').val();
     	data.bankCode = $('#bankCode').val();
     	if(id == ""){
     		url= '${basePath}/OtherInterviewConfigController/save';
     	}else{
     		url= '${basePath}/OtherInterviewConfigController/modify';
     		data.id = id;
     	}
    	$.dpAjax({
        	url:url,
            data: data,
            success: function (datas) {
                layer.closeAll();
                layer.msg("执行成功!", {icon: 6, time: 1000});
                return;
            }
        })
    }
    
    function cancelOrg() {
    	 layer.close(ywjigou);
    }
   
    var refresh = function () {
        $("#table_list_1").jqGrid("setGridParam", {search: true}).trigger("reloadGrid", [{page: 1}]);
    }
</script>
</body>
</html>
